/*
 * Copyright (c) 2012 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.libermundi.theorcs.chronicles.model.message.impl;

import java.util.Date;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Lob;
import javax.persistence.MappedSuperclass;

import org.hibernate.search.annotations.Analyzer;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Index;
import org.hibernate.search.annotations.Store;
import org.libermundi.theorcs.chronicles.model.message.Message;
import org.libermundi.theorcs.core.model.Searchable;
import org.libermundi.theorcs.core.model.base.NumericIdEntity;

@MappedSuperclass
@Analyzer(definition = "SuggestionAnalyzer")
public abstract class AbstractMessage extends NumericIdEntity implements Message, Searchable {
	private static final long serialVersionUID = 7269124754089412990L;

	private static final String[] SEARCH_FIELDS = new String[]{Message.PROP_TITLE,Message.PROP_BODY};
	
	private String _title;
	private String _body;
	private Date _sendingDate;

	/*
	 * (non-Javadoc)
	 * @see org.libermundi.theorcs.chronicles.model.messenging.Message#getTitle()
	 */
	@Override
	@Basic
	@Column(name = Message.PROP_TITLE, length=255, nullable=false)
	@Field(index=Index.YES, store=Store.YES)
	public String getTitle() {
		return _title;
	}

	/*
	 * (non-Javadoc)
	 * @see org.libermundi.theorcs.chronicles.model.messenging.Message#getBody()
	 */
	@Override
	@Lob
	@Column(name=Message.PROP_BODY,nullable=false)
	@Field(index=Index.YES, store=Store.YES)
	public String getBody() {
		return _body;
	}

	@Override
	@Basic
	@Column(name=Message.PROP_SENDINGDATE,nullable=false)
	public Date getSendingDate() {
		return _sendingDate;
	}

	/*
	 * (non-Javadoc)
	 * @see org.libermundi.theorcs.chronicles.model.messenging.Message#setTitle(java.lang.String)
	 */
	@Override
	public void setTitle(String title) {
		this._title = title;
	}

	/*
	 * (non-Javadoc)
	 * @see org.libermundi.theorcs.chronicles.model.messenging.Message#setBody(java.lang.String)
	 */
	@Override
	public void setBody(String body) {
		this._body = body;
	}

	@Override
	public void setSendingDate(Date sendingDate) {
		this._sendingDate = sendingDate;
	}

	/* (non-Javadoc)
	 * @see org.libermundi.theorcs.core.model.Searchable#loadSearchfields()
	 */
	@Override
	public String[] loadSearchfields() {
		return SEARCH_FIELDS;
	}
}
